<?php
session_start();

class test_core {
	private static $_inst = null;
	private $_name = null;
	
	public static function getInst() {
		ob_start();
		var_dump($_SESSION);
		$msg = ob_get_clean();
		ob_end_clean();
		echo 'dump of $session: '.$msg.' ...<br />';
		
		ob_start();
		var_dump(self::$_inst);
		$msg = ob_get_clean();
		ob_end_clean();
		echo 'dump of $_inst: '.$msg.' ...<br />';
		
		if(isset($_SESSION['application']) && $_SESSION['application'] != NULL) {
			self::$_inst = $_SESSION['application'];
		}
		
		if(!(self::$_inst instanceof self)) {
			self::$_inst = new self();
			$_SESSION['application'] = self::$_inst;
		}
		return self::$_inst;
	}
	
	private function __construct() {
		echo 'Construct ...<br />';
		$this->_init();
	}
	
	private function _init() {
		echo 'Initial ...<br />';
		$this->_name = microtime();
	}
	
	//__clone方法防止对象被复制克隆
	public function __clone() {
		trigger_error('Clone is not allow!',E_USER_ERROR);
	}
	
	public function dosth() {
		echo 'Hello '.$this->_name.'...<br />';
	}
}

$inst = test_core::getInst();
$inst->dosth();

// sleep(1);
// $inst = test_core::getInst();
// $inst->dosth();

// sleep(1);
// $inst = test_core::getInst();
// $inst->dosth();
